package cn.itcast.oa.service.impl;

import cn.itcast.oa.base.BaseAction;
import cn.itcast.oa.dao.DepartmentDao;
import cn.itcast.oa.domain.Department;
import cn.itcast.oa.domain.Role;
import cn.itcast.oa.service.DepartmentService;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by sin7cos7@163.com on 2016/12/5.
 */
@Service
@Transactional
public class DepartmentServiceImpl extends BaseAction<Department> implements DepartmentService {
    @Autowired
    private DepartmentDao departmentDao;
    @Resource
    private SessionFactory sessionFactory;



    @Override
    public void delete(Long id) {

    }

    @Override
    public void save(Department model) {

    }

    @Override
    public Department getById(Long id) {
        return null;
    }

    @Override
    public void update(Department department) {

    }



    @Override
    public List<Department> findTopList() {
        return sessionFactory.getCurrentSession().createQuery("from Department d where d.parent is null").list();
    }

    @Override

    public List<Department> findChildren(Long parentId) {
        return sessionFactory.getCurrentSession().createQuery(//
                "FROM Department d WHERE d.parent.id=?")//
                .setParameter(0, parentId)//
                .list();
    }
}
